<?php

class Db {
	private $dbh;

	const DB_HOST = "localhost";
	const DB_USER = "root";
	const DB_PASS = "";
	const DB_NAME = "battleship";

	public function __construct(){
		$this->connect();
	}
	public function getDbh(){
		return $this->dbh;
	}
	public function connect(){
		try {

			$this->dbh = new PDO('mysql:host='.Db::DB_HOST.';dbname='.Db::DB_NAME, Db::DB_USER, Db::DB_PASS, array(
				PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
				PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
				PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING
			));

		} catch (PDOException $e) {
			echo 'Erreur de connexion : ' . $e->getMessage();
		}
	}

}